﻿@* 数据访问层测试 - 模拟数据服务 *@
@using Util.Generators
@using Util.Generators.Helpers
@model Util.Generators.Contexts.EntityContext
@{
    var service = new GenerateService( Model );
    var entity = service.EntityName;
    var fakeService = $"{entity}FakeService";
    var description = Model.Description;
    Model.Output.FileNameNoExtension = fakeService;
    Model.Output.Extension = ".cs";
    Model.Output.RelativeRootPath = $"test/{service.GetDataTestProjectPath( Util.Data.DatabaseType.Oracle, "Fakes", true )}";
}
using @service.GetDomainNamespace( "Models" );

namespace @service.GetDataTestNamespace( Util.Data.DatabaseType.Oracle,"Fakes",true );

/// <summary>
/// @(description)模拟数据服务
/// </summary>
public static class @fakeService {
    /// <summary>
    /// 获取@(description)
    /// </summary>
    public static @entity Get@(entity)() {
        return Get@(Model.PluralName)( 1 ).First();
    }

    /// <summary>
    /// 获取@(description)列表
    /// </summary>
    /// <param name="count">行数</param>
    public static List<@entity> Get@(Model.PluralName)( int count ) {
        return new AutoFaker<@entity>()
            @foreach( var property in Model.Properties ) {
            @if ( property.IsExtraProperties ) {
                continue;
            }
            @if ( property.IsVersion ) {
                continue;
            }
            @if ( property.MaxLength == -1 ) {
                continue;
            }
            @if ( property.IsKey ) {
                continue;
            }
            @if ( property.IsTree ) {
            @:.Ignore( t => t.@property.Name )
                continue;
            }
            @if ( property.IsDeleted ) {
            @:.RuleFor( t => t.IsDeleted, false )
                continue;
            } 
            @if ( property.SystemType == SystemType.String ) {
            @:.RuleFor( t => t.@property.Name,t => t.Random.String2( 1,@property.GetSafeMaxLength() ) )
                continue;
            }
            }
            .Generate( count );
    }
}